﻿
@{
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/layuimini-v2/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/layuimini-v2/css/public.css" media="all">
    <link rel="stylesheet" href="/layuimini-v2/lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
    <div class="layui-form layuimini-form">
        <div class="layui-form-item">
            <label class="layui-form-label required">菜单名</label>
            <div class="layui-input-block">
                <input type="text" name="Title" lay-verify="required" lay-reqtext="用户名不能为空" placeholder="请输入用户名" value="" class="layui-input">
            </div>
        </div>
@*        <img src="~/App_Data/img/1.jpg" />*@
        @*        <div class="layui-form-item">
                <label class="layui-form-label">父ID</label>
                <div class="layui-input-block">
                    <input type="text" name="Pid" lay-reqtext="用户名不能为空" placeholder="请父ID" value="" class="layui-input">
                </div>
            </div>*@

        <div class="layui-form-item">
            <label class="layui-form-label">父ID</label>
            <div class="layui-input-block">
                <input type="text" name="Pid" placeholder="请输入" autocomplete="off" class="layui-input" id="demo2">
            </div>
        </div>

        @*<div class="layui-form-item">
                <label class="layui-form-label">图标</label>
                <div class="layui-input-block">
                    <input type="text" name="Icon" placeholder="请输入图标编号" value="" class="layui-input">
                </div>
            </div>*@

        <div class="layui-form-item">
            <label for="" class="layui-form-label">图标</label>
            <div class="layui-input-block">
                <input type="text" id="Icon" name="Icon" lay-filter="Icon" class="hide" value="">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">页面链接</label>
            <div class="layui-input-block">
                <input type="text" name="Href" placeholder="请输入链接" value="" class="layui-input">
            </div>
        </div>


        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
            </div>
        </div>
    </div>
    <script src="/layuimini-v2/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
    <script src="/layuimini-v2/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
    <script>
        layui.use(['form', 'tableSelect', 'table', 'iconPickerFa','layer'], function () {
        var form = layui.form,
            layer = layui.layer,
            table = layui.table,
            iconPickerFa = layui.iconPickerFa,
            tableSelect = layui.tableSelect,
            $ = layui.$;


            iconPickerFa.render({
                // 选择器，推荐使用input
                elem: '#Icon',
                // fa 图标接口
                url: "/layuimini-v2/lib/font-awesome-4.7.0/less/variables.less",
                // 是否开启搜索：true/false，默认true
                search: true,
                // 是否开启分页：true/false，默认true
                page: true,
                // 每页显示数量，默认12
                limit: 12,
                // 点击回调
                click: function (data) {
                    console.log(data);
                },
                // 渲染成功后的回调
                success: function (d) {
                    console.log(d);
                }
            });

        tableSelect.render({
            elem: '#demo2',
            checkedKey: 'id',
            table: {
                url: '@Url.Action("GettableSelectList")',
                limits: [6, 10, 20, 30, 50, 100],
                limit: 6,
                cols: [[
                    { type: 'radio' },
                    @*{ field: 'Item1', title: 'ID'},*@
                    { field: 'Item2', title: '菜单名' }
                ]]
            },
            done: function (elem, data) {
                var NEWJSON = []
                layui.each(data.data, function (index, item) {
                    NEWJSON.push(item.Item1)
                })
                elem.val(NEWJSON.join(","))
            }
        })

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var data = data.field;
            var icon1 = "fa " + data.Icon;
            var index = layer.alert("确认信息无误吗", {
                title: '确认'
            }, function () {

				$.ajax({
					url: "@Url.Action("AddMunes")",
					type: "post",
                    data: { "Title": data.Title, "Pid": data.Pid, "Icon": icon1, "Href": data.Href },
					success: function (da) {
						console.log(da)
						layer.msg(da.msg)

					},
				})
                // 关闭弹出层
                layer.close(index);

                var iframeIndex = parent.layer.getFrameIndex(window.name);
                parent.location.reload();
                parent.layer.close(iframeIndex);

            });



            return false;
        });

    });
    </script>
</body>
</html>